<template>
  <div class="login">
      <div class="login_box">
            <div class="avater_box">
                <img src="../assets/images/logo.png" alt="">
            </div>
            <el-form label-width="0px" class="login_form" :model="loginForm" :rules="loginFormRules" ref="loginFormRef">
                <el-form-item prop="username">
                    <el-input prefix-icon="el-icon-s-custom" v-model="loginForm.username"></el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input prefix-icon="el-icon-key" v-model="loginForm.password" type="password"></el-input>
                </el-form-item>
                <el-form-item class="btns">
                    <el-button type="primary" @click="login">登录</el-button>
                    <el-button type="info" @click="resetLoginForm">重置</el-button>
                </el-form-item>
            </el-form>
      </div>
  </div>
</template>

<script>
export default {
    data() {
        return{
            loginForm:{
                username:"admin",
                password:"123456"
            },
            //表单验证规则
            loginFormRules:{
                username:[
                    { required: true, message: '请输入用户名', trigger: 'blur' },
                    { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
                ],
                password:[
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { min: 6, max: 10, message: '长度在 6 到 10 个字符', trigger: 'blur' }
                ]
            }
        }
    },
    methods: {
        resetLoginForm(){
           this.loginForm.username = "admin";
           this.loginForm.password = "123456";
        },
        login(){
            this.$refs.loginFormRef.validate((valid)=>{
                console.log(valid)
                if(valid){
                    sessionStorage.setItem("key","1122")
                    this.$message.success("登录成功!")
                    this.$router.push('/home')
                }else{
                    this.$message.error("登录失败!")
                }
            })
        }
    }
}
</script>

<style scoped>
.login{
    background-color:#373d41;
    height: 100%;
}
.login_box{
    width:450px;
    height: 300px;
    position: absolute;
    background-color: #fff;
    border-radius:5px;
    top:50%;
    left:50%;
    transform: translate(-50%,-50%);
}
.avater_box{
    height: 130px;
    width:130px;
    border:1px solid #eee;
    padding: 10px;
    box-shadow: 0 0 10px #ddd;
    border-radius: 50%;
    position: absolute;
    left:50%;
    transform: translate(-50%,-50%);
    background-color: #fff;
}
.avater_box img{
    width:100%;
    height:100%;
    border-radius: 50%;
    background-color:#eee;
}
.btns{
    display: flex;
    justify-content: flex-end;
}
.login_form{
    position:absolute;
    bottom: 0;
    padding:0 20px;
    width:100%;
    box-sizing: border-box;
}
</style>